﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NextViewer
{
    class Stat<T>
    {
        private T[] data;
        private int count;
        public int Count
        {
            get { return count; }
        }

        public Stat(int size)
        {
            data = new T[size];
        }
        public void Add(T val)
        {
            data[count] = val;
            count++;
        }
        public double GetAvr()
        {
            double avr=0;

            for (int i = 0; i < count; i++)
            {
                avr += double.Parse(data[i].ToString());
            }
            return avr / count;
        }
        public double GetMax()
        {
            double max = -99999.9;
            for (int i = 0; i < count; i++)
            {
                if (max < double.Parse(data[i].ToString()))
                {
                    max = double.Parse(data[i].ToString());
                }
            }
            return max;
        }
        public double GetMin()
        {
            double min = 9999999.9;
            for (int i = 0; i < count; i++)
            {
                if (min > double.Parse(data[i].ToString()))
                {
                    min = double.Parse(data[i].ToString());
                }
            }
            return min;
        }
        public double GetStdev()
        {
            double stdev = 0;
            double avr = GetAvr();

            for (int i = 0; i < count; i++)
            {
                double temp = double.Parse(data[i].ToString()) - avr;
                stdev += temp * temp;
            }

            stdev = Math.Sqrt(stdev / count);
            return stdev;
        }
    }

    class Stats<T>
    {
        private List<T> data;
        
        public int Count
        {
            get { return data.Count; }
        }

        public Stats()
        {
            data = new List<T>();
        }
        public void Add(T val)
        {
            data.Add( val);
        }
        public double GetAvr()
        {
            double avr = 0;

            for (int i = 0; i < data.Count; i++)
            {
                avr += double.Parse(data[i].ToString());
            }
            return avr / data.Count;
        }
        public double GetMax()
        {
            double max = -99999.9;
            for (int i = 0; i < data.Count; i++)
            {
                if (max < double.Parse(data[i].ToString()))
                {
                    max = double.Parse(data[i].ToString());
                }
            }
            return max;
        }
        public double GetMin()
        {
            double min = 9999999.9;
            for (int i = 0; i < data.Count; i++)
            {
                if (min > double.Parse(data[i].ToString()))
                {
                    min = double.Parse(data[i].ToString());
                }
            }
            return min;
        }
        public double GetStdev()
        {
            double stdev = 0;
            double avr = GetAvr();

            for (int i = 0; i < data.Count; i++)
            {
                double temp = double.Parse(data[i].ToString()) - avr;
                stdev += temp * temp;
            }

            stdev = Math.Sqrt(stdev / data.Count);
            return stdev;
        }
    }
}
